package com.share.rabbitmq;

import com.rabbitmq.client.*;

/**
 * author:caifan
 * date:2019/8/10
 */
public class Receive {
    private static final String QUEUE_NAME = "hello";
    private static final String HOST = "192.168.2.15";
    private static final int PORT = 5672;

    public static void main(String[] args) {
        connect();
    }

    public static void connect() {
        try (Connection connection = RabbitMQConnect.connect();
            Channel channel = connection.createChannel();) {
            channel.queueDeclare(QUEUE_NAME, false, false, false, null);
            DeliverCallback deliverCallback = ((consumerTag, message) -> {
                String msg = new String(message.getBody(), "UTF-8");
                System.out.println("receive:" + msg);
            });
            channel.basicConsume(QUEUE_NAME, true, deliverCallback, consumerTag -> {});
//            Consumer consumer = new DefaultConsumer(channel);
//            consumer.handleRecoverOk("hehe");

//            channel.basicConsume(QUEUE_NAME, consumer);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
